
class Connection
  
  def initialize(flightnr, departure, duration,day)
    @flightnr = flightnr
    @departure = departure
    @duration = duration
    @day = day
  end
  
  def flightnr
    return @flightnr
  end
  
  def departure
    return @departure
  end
  
  def duration
    return @duration
  end

  # @return The day this connection stars
  def departure_date
    return @day
  end

  ## @return the arrival time of the plain
  ## @effect return (departure + duration)
  def arrival
    new_time = SimpleTime.new(@departure.hour, @departure.minute)
    new_time.add_as_time(duration)
    return new_time
  end

  # @return The day that this connection will arrive on
  def arrival_date
    return (Date.parse(@day) + day_count).to_s
  end

  # @return the amount of days the connection is passing
  def day_count
    a_days = duration.hour/24
    if(arrival.before?(departure))
      a_days+=1
    end
    return a_days
  end

  def to_s
    return @flightnr + ", departure: " + @departure.to_s + ", duration: " + @duration.to_s+ ", on: "+ @day.to_s
  end
  
end
